

class writeTest():
    def __init__(self, file_name):
        self.file_name = file_name
        self.test = open(self.file_name, 'w+')
        self.test.close()
    
    def write(self, data):        
        self.test = open(self.file_name, 'a+')
        self.test.write(str(data) + '\n')
        self.test.close()

    def read(self):
        self.test = open(self.file_name, 'r')
        lines = []
        for line in self.test:        
            lines.append(int(line.split('\\')[0]))
        self.test.close()
        return lines
    
    def paint(self):
        from loadLabels import LoadLabels as lls
        from matplotlib import pyplot as plt 

        scales = self.read()
        sum = len(scales)
        scale_hist = {}
        for scale in scales:
            if scale in scale_hist:
                scale_hist[scale] += 1
            else:
                scale_hist[scale] = 1

        x = list(scale_hist.keys())
        y = list(scale_hist.values())

        max_scale = 20
        small_sum = 0
        for _x in x:
            if _x <= max_scale:
                small_sum += scale_hist[_x]
        print(sum, small_sum, small_sum/sum)

        plt.bar(x, y)
        plt.xlim(min(x), max_scale)
        plt.show()


if __name__ == '__main__':
    test = writeTest('test')
    for i in range(100):
        test.write(i)
    print(test.read())
    # test.paint()